package com.chatplus.application.web;

import com.chatplus.application.web.interceptor.AuditLoggerFilter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * TODO
 *
 * @author chj
 * @date 2022/6/28
 **/
@Configuration
public class AuditLoggerFilterConfiguration {

    @Bean
    @ConfigurationProperties("qbzg.turnright.auditlogger")
    public AuditLoggerProperties auditLoggerProperties() {
        return new AuditLoggerProperties();
    }

    @Bean
    public FilterRegistrationBean<AuditLoggerFilter> reqResFilter() {
        FilterRegistrationBean<AuditLoggerFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new AuditLoggerFilter());
        filterRegistrationBean.addUrlPatterns("/*");//配置过滤规则
        return filterRegistrationBean;
    }

    public static class AuditLoggerProperties {

        private boolean enable = true;

        public boolean isEnable() {
            return enable;
        }

        public void setEnable(boolean enable) {
            this.enable = enable;
        }
    }
}
